##import urllib.request as ur
####这个网站好像访问速度很慢，所以下载不下来
##response = ur.urlopen('http://placekitten.com/300/300')
##cat_img = response.read()
##
##with open('cat_500_600.jpg', 'wb') as f:
##    f.write(cat_img)

##EASYgui版本
    
import urllib.request as ur
import easygui as eg
msg = "请填写喵的尺寸"
title = "下载一只喵"
fieldName = ["宽:", "高:"]
value = ["400","600"]
fieldValues = eg.multenterbox(msg,title,fieldName,value)
while True:
    if fieldValues == None:
        break
    errmsg = ""

    try:
        fieldValues[0] = int(fieldValues[0].strip())
    except:
        errmsg += "宽度必须为整数！"

    try:
        fieldValues[1] = int(fieldValues[1].strip())
    except:
        errmsg += "宽度必须为整数！"

    if errmsg == "":
        break

    fieldValues = eg.multenterbox(errmsg,title,fieldName,fieldValues)

response = ur.urlopen('http://placekitten.com/%s/%s' % (fieldValues[0], fieldValues[1]))
cat_img = response.read()

save_path = eg.diropenbox(msg=None, title='您要将喵保存至哪里呢？', default=None)
with open(('%s' % save_path + '\cat_%s_%s.jpg' % (fieldValues[0], fieldValues[1])), 'wb') as f:
    f.write(cat_img)
if __name__ == "__main__":
    main()
